package com.tms.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tms.basic.pojo.domain.Position;
import com.tms.basic.mapper.PositionMapper;
import com.tms.basic.service.PositionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {

    @Override
    public Page<Position> listPositions(Page<Position> page, Position position) {
        LambdaQueryWrapper<Position> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(position.getPositionCode()), Position::getPositionCode, position.getPositionCode())
              .like(StringUtils.isNotBlank(position.getPositionName()), Position::getPositionName, position.getPositionName())
              .eq(position.getDeptId() != null, Position::getDeptId, position.getDeptId())
              .eq(position.getStatus() != null, Position::getStatus, position.getStatus())
              .orderByAsc(Position::getSort);
        return this.page(page, wrapper);
    }

    @Override
    public boolean createPosition(Position position) {
        return this.save(position);
    }

    @Override
    public boolean updatePosition(Position position) {
        return this.updateById(position);
    }

    @Override
    public boolean deletePosition(Long id) {
        return this.removeById(id);
    }
}